package leetcode.editor.utils;

public class TreeNodeUtil {
    /**
     * 求最大深度
     */
    public int getDepth(TreeNode node) {
        if (node == null)
            return 0;
        return 1 + Math.max(getDepth(node.left), getDepth(node.right));
    }

    /**
     * 判断node是否为child祖先
     */
    public boolean isAncestor(TreeNode node, TreeNode child) {
        if (node == null || child == null)
            return false;
        if (node == child)
            return true;
        return isAncestor(node.left, child) || isAncestor(node.right, child);
    }
}
